package cn.aiszs.javafx_imp.service;

import cn.aiszs.javafx_imp.mapper.IPMapper;
import cn.aiszs.javafx_imp.pojo.Ip;
import cn.aiszs.javafx_imp.pojo.Oil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class IPService {
    @Autowired
    private IPMapper ipMapper;

    @Autowired
    private Ip ip;

    public Integer insertData(String data){
        JSONObject jsonObject = JSON.parseObject(data);//Json字符串解析成对象
        ip = new Ip();
        ip.setIpIp(jsonObject.getJSONObject("data").getString("ip"));
        ip.setIpAddress(jsonObject.getJSONObject("data").getString("location"));
        return ipMapper.insertOne(ip);
    }

    public Boolean is_exist(String ip){
        QueryWrapper<Ip> wrapper = new QueryWrapper<>();
        wrapper.eq("ip_ip",ip);
        Ip ip1= ipMapper.selectOne(wrapper);
        return ipMapper.selectOne(wrapper)!=null;
    }

    public Ip selectByIp(String ip){
        return ipMapper.findIp(ip);
    }
}
